import RenderUtils from '../RenderUtils'
import {RenderTypeItem} from "../ConfigType";

const inputNumber: RenderTypeItem = {
  name: 'inputRange',
  components: {
    // @ts-ignore
    InputRange: () => import('../components/InputRange'),
  },
  /**
   * 初始化自己的绑定值
   * @param vm
   * @param formItem
   */
  initFormValue(vm, formItem) {
    vm.$set(vm.formData, formItem.prop, {min: undefined, max: undefined})
  },
  /**
   *
   * @param createElement
   * @param vm
   * @param formItem
   * @return {VNode[]}
   */
  render(createElement, vm, formItem) {
    const config = RenderUtils.getConfig(vm, formItem, {
      props: {
        placeholder: `请输入${formItem.label}的范围`,
        propsMin: {
          placeholder: `请输入${formItem.label}的最小值`,
          ...formItem?.props?.propsMin
        },
        propsMax: {
          placeholder: `请输入${formItem.label}的最大值`,
          ...formItem?.props?.propsMax
        },
        eventsMin: {
          ...formItem?.props?.eventsMin
        },
        eventsMax: {
          ...formItem?.props?.eventsMax
        },
      },
    }, this)
    return [
      createElement(`inputRange`, config)
    ]
  }
}

export default inputNumber
